package cn.soft863.servlet.back;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.websocket.Session;

import cn.soft863.common.servlet.BaseServlet;

/**
 * 管理员登陆成功后的操作
 * @author 902-B-Book
 *
 */
public class AdminsBackServlet extends BaseServlet
{
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		System.out.println("----service------");
		/* 专门接收一个method,*/
		String method = request.getParameter("method");
		if("main".equalsIgnoreCase(method))
		{
			/* 登陆后的首页 */
			this.main(request,response);
		}else if("loginOut".equalsIgnoreCase(method)) {
			this.loginOut(request,response);
		}
	}

	private void loginOut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		System.out.println("-----main-----");
		HttpSession session = request.getSession();
		session.removeAttribute("admins");
		
		url = "/WEB-INF/jsp/back/adminsLogin.jsp" ; 
		/* 服务器端跳转到登陆成功页面 */
		request.getRequestDispatcher(url).forward(request, response);
		
	}

	/**
	 * 登陆后的首页
	 * @param request
	 * @param response
	 * @throws IOException 
	 * @throws ServletException 
	 */
	private void main(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		System.out.println("-----main-----");
		url = "/WEB-INF/jsp/back/admins/main.jsp" ; 
		/* 服务器端跳转到登陆成功页面 */
		request.getRequestDispatcher(url).forward(request, response);
	}
}
